<?php
/**
 * +----------------------------------------------------------------------
 * | 表单验证器
 * +----------------------------------------------------------------------
 *                      _ooOoo_
 *                     o8888888o            | AUTHOR: 杜云
 *                     88" . "88            | EMAIL: 987772927@qq.com
 *                     (| -_- |)            | QQ: 987772927
 *                     O\  =  /O            | WECHAT: 987772927
 *                  ____/`---'\____
 *                .'  \\|     |//  `.
 *               /  \\|||  :  |||//  \
 *              /  _||||| -:- |||||-  \
 *              |   | \\\  -  /// |   |
 *              | \_|  ''\-/''  |   |
 *              \  .-\__  `-`  ___/-. /
 *            ___`. .'  /-.-\  `. . __
 *         ."" '<  `.___\_<|>_/___.'  >'"".
 *        | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *        \  \ `-.   \_ __\ /__ _/   .-` /  /
 *   ======`-.____`-.___\_____/___.-`____.-'======
 *                      `=-='
 * +----------------------------------------------------------------------
 */
declare(strict_types=1);
namespace App\Request;

use Hyperf\Validation\Request\FormRequest;

class UserRequest extends FormRequest
{

    public function authorize(): bool
    {
        return true;
    } 
    public function rules(): array
    {
        return [
            'account' => ['required','string','max:50','unique:users'],
            'realname' => ['required','string','max:20'],
            'phone' => ['required','string','max:11','regex:/^1[^0-2]\d{9}$/'],
            'type' => ['required'],
            'idcard' => ['required','regex:/^([1-9]\d{5})(19\d{2}|20\d{2})(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i'],
            'password' => ['required','string','min:6'],
            'role_ids' => ['required'],
        ];
    }
    public function attributes(): array
    {
        return [
            'account' => '用户账号',
            'realname' => '真实姓名',
            'phone' => '手机号',
            'age' => '年龄',
            'idcard' => '身份证号',
            'type' => '身份类型',
            'password' => '密码',
            'role_ids' => '角色',
        ];
    }
    public function messages(): array
    {
        return [
            'account.unique' => ':attribute已存在',
            'phone.unique' => ':attribute已存在',
            'phone.regex' => ':attribute格式有误',
        ];
    }
    protected $scenes = [
        'add' => ['account','realname','phone','type','password','role_ids'],
        'edit' => ['id'/*,'birthday'*/,'role_ids'],
    ];
}
